---
title: "Replication material"
subtitle: "How the refugee crisis and radical right parties shape party competition on immigration"
author: "Theresa Gessler^[University of Zurich, Department of Political Science, gessler@ipz.uzh.ch] & Sophia Hunger^[WZB Berlin Social Science Center, Center for Civil Society Research, sophia.hunger@wzb.eu]"
abstract: \singlespacing The 2015 refugee crisis had a major impact on public debate and election outcomes across Europe. However, we understand little about its impact on political competition, given the different starting points and trajectories of European countries. This paper analyses how parties changed their issue emphasis and positional strategy regarding immigration before, during, and after the refugee crisis. Our study is based on a corpus of 120,000 party press releases between 2013 and 2017 from Austria, Germany, and Switzerland. We identify immigration-related press releases using a novel dictionary and estimate parties' positions through Wordscores. The resulting monthly measures of salience and positions allow for studying changes in close time-intervals, providing crucial detail for disentangling the impact of the crisis itself and the contribution of right-wing parties. While we provide evidence that attention to immigration increased drastically for all parties during the crisis, radical right parties remained issue owners and drove the attention of mainstream parties. However, the attention of mainstream parties to immigration decreased towards the end of the refugee crisis and we only find limited evidence of these parties accommodating the positions of the radical right. 
keywords: "refugee crisis, immigration, party competition, radical right parties, text-as-data"
date: "Last compiled: `r Sys.Date()`"
output: 
    html_document:
        toc: true
        code_folding: hide
---



```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = T,
                      warning = FALSE,
                      message = FALSE,
                      comment=FALSE,
                      cache=FALSE,
                      fig.pos='H')
p_needed <- c("plyr", "dplyr", "quanteda","lubridate","stringr","ggplot2","car", "knitr", "kableExtra", "carData","tidyr", "stargazer", "broom", "zoo", "cowplot", "xml2", "rvest", "magrittr", "ggrepel","viridis", "readxl")
lapply(p_needed, require, character.only = TRUE)



party_names_at<-c("FPÖ","Greens","NEOS","ÖVP","Pilz","SPÖ")
party_names_de<-c("AfD","CDU","CSU","FDP","Greens","Left Party","SPD")
party_names_ch<-c("BDP","CVP","FDP","Greenliberals","Greens","SP","SVP")
names(party_names_at)<-c("fpo","gruene","neos","ovp","pilz","spo")
names(party_names_de)<-c("afd","cdu","csu","fdp","gruene","linke","spd")
names(party_names_ch)<-c("bdp","cvp","fdp_ch","greenliberals","greens_ch","sp","svp")
```






```{r caseselec_sal, fig.align='center', fig.cap="\\label{caseselec1}Salience of immigration in 14 European countries over time",fig.pos="!htp"}
# load iso codes from Wikipedia
iso_codes <- read_html("https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes") %>% html_table(fill=T,header=F) %>% extract2(1)

# load Polcon-coresentence data and prepare for graph
coresentences <- haven::read_dta("coresentences_data_190718_clean.dta")
labels <- attributes(coresentences$country)$labels
labels=data.frame(countryname=names(labels),
                  country=labels,
                  stringsAsFactors = F)
coresentences <- coresentences %>% left_join(labels) %>%
  dplyr::rename(countrynumber=country,country=countryname)%>%
  left_join(iso_codes %>% dplyr::select(X1,X4),by=c("country"="X1")) %>%
  mutate(alpha=ifelse(country %in% c("Germany","Austria","Switzerland"),1,0.2)) %>%
  mutate(X4=ifelse(is.na(X4),case_when(country=="Netherlands"~"NL",country=="Britain"~"UK",country=="France"~"FR",country=="Czech Republic"~"CZ"),X4))

weighted <- coresentences %>% dplyr::filter(count>5) %>%
  group_by(X4,year_election,alpha,country) %>% 
  dplyr::summarize(weighted.salience = weighted.mean(salience, weights = count)) %>%
  dplyr::filter(year_election>2000)

# prepare ribbon
gg <- ggplot()+
  stat_smooth(data=weighted ,aes(x=year_election,y=weighted.salience),method='loess')

rib_data <- ggplot_build(gg)$data[[1]]

# final graph for salience
ggplot()+
  geom_point(data=weighted %>% dplyr::filter(alpha==0.2),aes(x=year_election,y=weighted.salience),alpha=0.3)+
  geom_point(data=weighted %>% dplyr::filter(alpha==1),aes(x=year_election,y=weighted.salience,color=country))+
  geom_line(data=weighted %>% dplyr::filter(alpha==1),aes(x=year_election,y=weighted.salience,color=country,linetype=country))+
  geom_text_repel(data=weighted %>% dplyr::filter(weighted.salience>5), aes(x=year_election,y=weighted.salience,label=X4,alpha=alpha))+
  xlab("Year")+ylab("Weighted average salience in party system")+
  #ggtitle("Development of salience of immigration issues over time")+
  geom_vline(aes(xintercept=2015))+theme_minimal()+scale_alpha(range=c(0.3,1),guide=F)+
  geom_ribbon(data=rib_data,aes(x=x,ymin=ymin,ymax=ymax),color="black",
                fill=NA,linetype=9)+
  #geom_smooth(data=weighted,aes(x=year_election,y=weighted.salience),fill=NA,color="gray")+
  coord_cartesian(ylim = c(0,20)) +
  scale_color_viridis(discrete=T)


```



```{r caseselec_arrivals, fig.align='center', fig.cap="\\label{caseselec2}Annual Asylum applications in 14 European countries",fig.pos="!htp"}


# load arrival data (source: https://en.wikipedia.org/wiki/European_migrant_crisis#Statistics)
arrivals <- read_xlsx("refugee_EU28.xlsx")


# prepare data on refugee numbers for plotting
arrivals_long <- arrivals %>% dplyr::filter(Year!="EU28" & Year!="Total") %>% 
  gather("year","number",-Year) %>% dplyr::rename(country=Year)%>% mutate(number=str_replace_all(number,",",""))%>%
  mutate(alpha=ifelse(country %in% c("Germany","Austria","Switzerland"),1,0)) %>%
  mutate(number=as.numeric(number),year=as.numeric(year)) %>%
  left_join(iso_codes %>% dplyr::select(X1,X4),by=c("country"="X1")) %>%
  mutate(X4=ifelse(is.na(X4),case_when(country=="Netherlands"~"NL",country=="United Kingdom"~"UK",country=="France"~"FR",country=="Czech Republic"~"CZ"),X4))


# standardizing arrivals by country

pop <- read_excel("pop_EU28_new.xls")
# reshape
pop_long <- pop %>% gather("year","pop",-country)
pop_long$year <- as.numeric(pop_long$year)
arrivals_long <- dplyr::filter(arrivals_long, X4 %in% coresentences$X4)
# combine
arrivals_long2 <- left_join(arrivals_long, pop_long)
arrivals_long2 <- arrivals_long2 %>% 
  mutate(number_st = number/(pop/100000))

# prepare ribbon
gg <- ggplot()+
  stat_smooth(data=arrivals_long2 
  	,aes(x=year,y=number_st),method='loess',span=0.2)
rib_data <- ggplot_build(gg)$data[[1]]

# final graph
ggplot()+
  geom_line(data=arrivals_long2 %>% dplyr::filter(alpha==1),aes(color=country,x=year,y=number_st,group=country,linetype=country)) +
    geom_text_repel(data=arrivals_long2 %>% dplyr::filter(number_st>700),aes(x=year,y=number_st,label=X4) ) +
geom_jitter(data=arrivals_long2 %>% dplyr::filter(alpha!=1),aes(x=year,y=number_st,group=country),alpha=0.3)+
  geom_point(data=arrivals_long2 %>% dplyr::filter(alpha==1),aes(color=country,x=year,y=number_st,group=country))+
  geom_ribbon(data=rib_data,aes(x=x,ymin=ymin,ymax=ymax),color="black",
                fill=NA,linetype=9)+
  theme_minimal()+theme(legend.position="bottom")+
  scale_y_continuous("Number of asylum applications by 100,000 of inhabitants", labels = scales::comma)+
  scale_x_continuous("Year")+theme_minimal() +
  scale_color_viridis(discrete=T)

  
```







```{r}

# load dfms for all three countries

load("ch_dfms.RData")
ch_overview<-docvars(ch_dfm) %>% dplyr::group_by(party,ym) %>%  dplyr::summarise(releases_n=n(),immig_releases_n=sum(gessler_hunger)) %>% group_by(party)%>%
dplyr::summarise(releases=sum(releases_n),avg=mean(releases_n),immig_releases_n=sum(immig_releases_n))


load("de_dfms.RData")
de_dfm<-dfm_subset(de_dfm,str_detect(docvars(de_dfm,"title"),"Interview")==FALSE)
de_overview<-docvars(de_dfm)%>% dplyr::group_by(party,ym) %>%  dplyr::summarise(releases_n=n(),immig_releases_n=sum(gessler_hunger)) %>% group_by(party)%>%
dplyr::summarise(releases=sum(releases_n),avg=mean(releases_n),immig_releases_n=sum(immig_releases_n))


load("at_dfms.RData")
at_overview<-docvars(at_dfm)%>% dplyr::group_by(party,ym) %>%  dplyr::summarise(releases_n=n(),immig_releases_n=sum(gessler_hunger)) %>% group_by(party)%>%
dplyr::summarise(releases=sum(releases_n),avg=mean(releases_n),immig_releases_n=sum(immig_releases_n))


# code for ovierview table in data section
full_overview<-bind_rows(at_overview,de_overview,ch_overview,.id="country") %>%
  mutate(country=car::recode(country,"1='Austria';2='Germany';3='Switzerland'")) %>%
  dplyr::rename(PR=releases,Imm=immig_releases_n) %>%
  mutate(sal=Imm/PR*100,party=car::recode(party,"'pilz'='Pilz';'gruene'='Green Party';'spo'='SPÖ';'ovp'='OVP';'fpo'='FPÖ';'neos'='NEOS';'afd'='AfD';'linke'='Left Party';'spd'='SPD';'cdu'='CDU';'fdp'='FDP';'csu'='CSU';'bdp'='BDP';'fdp_ch'='FDP';'greens_ch'='Green Party';'svp'='SVP';'cvp'='CVP';'greenliberals'='Green Liberal Party';'sp'='SPS'"))


full_overview =full_overview %>% dplyr::select(-c(country))
knitr::kable(full_overview, format='html', booktab = T, caption = "\\label{tab:nopr}Number of press releases", digits=1, col.names = c("party", "N (Total)","monthly", "N (immigration)", "Salience"))%>% kableExtra::kable_styling() %>% group_rows("Austria", 1, 6) %>%
 group_rows("Germany", 7, 13) %>% group_rows("Switzerland", 14, 20)


```



# Results
## The rising salience of immigration



```{r salience-figure-multiple-2, fig.align='center', fig.cap="\\label{fig:sal}Estimated salience of immigration in 3 countries",fig.width=8,fig.height=12,fig.pos="!htp"}

# main graphs for salience 

# Austria
load("at_dfms.RData")
at_<-docvars(at_dfm)
at_$gessler_hunger=at_$gessler_hunger*100
at_<-at_ %>% group_by(party,ym) %>% dplyr::mutate(total=dplyr::n()) %>% subset(total>4)

at_$time<- as.Date(paste0("20",at_$ym,"-01"), "%Y-%m-%d")
at_<-subset(at_,at_$time<as.Date("2018-03-31"))
at2<-at_ %>% dplyr::rename(party2=party)

at_plot<-ggplot(data=at_,mapping=aes(x=time,y=gessler_hunger))+
  geom_smooth(data=at2,mapping=aes(x=time,y=gessler_hunger,group=party2),alpha=0.6,method="loess",color="gray",se=F,size=0.3)+
 geom_smooth(mapping=aes(x=date,alpha=0.25,fill=party,color=party),method="loess",size=0.5)+
    stat_summary(fun.y="mean",geom="point",size=1,aes(color=party))+
scale_x_date(name="Date", date_breaks = "year", date_labels="%Y")+
 scale_y_continuous(name="Salience in %") +theme_minimal()+ theme(legend.position="none")+
  scale_color_manual(name="Party", values=c("cornflowerblue","seagreen","purple","black","dimgray","red"))+
 scale_fill_manual(values=c("cornflowerblue","seagreen","purple","black","dimgray","red"))+
 ggtitle("Salience of immigration in Austria")+facet_wrap(~party,labeller=labeller(party=party_names_at))+
 coord_cartesian(ylim=c(0,100))+
  geom_vline(aes(xintercept=as.Date("2015-07-01")),linetype="dashed")

# Germany
load("de_dfms.RData")

de_<-docvars(de_dfm)
de_$gessler_hunger=de_$gessler_hunger*100
de_<-de_ %>% group_by(party,ym) %>% dplyr::mutate(total=dplyr::n()) %>% subset(total>4)

de_$time<- as.Date(paste0("20",de_$ym,"-01"), "%Y-%m-%d")
de_<-subset(de_,de_$time<as.Date("2018-03-31"))
de2<-de_ %>% dplyr::rename(party2=party)

de_plot<-ggplot(data=de_,mapping=aes(x=time,y=gessler_hunger))+
geom_smooth(data=de2,mapping=aes(x=time,y=gessler_hunger,group=party2),alpha=0.6,method="loess",color="gray",se=F,size=0.3)+
 geom_smooth(mapping=aes(x=date,alpha=0.25,color=party,fill=party),method="loess",size=0.5)+
    stat_summary(fun.y="mean",geom="point",size=1,aes(color=party))+
scale_x_date(name="Date", date_breaks = "year", date_labels="%Y")+
 scale_y_continuous(name="Salience in %") +theme_minimal()+ theme(legend.position="none")+
  scale_color_manual(name="Party", values=c("cornflowerblue","black","dimgray","gold","seagreen","purple","red"))+
 scale_fill_manual(values=c("cornflowerblue","black","dimgray","gold","seagreen","purple","red"))+
 ggtitle("Salience of immigration in Germany")+facet_wrap(~party,labeller=labeller(party=party_names_de))+
 coord_cartesian(ylim=c(0,100))+
  geom_vline(aes(xintercept=as.Date("2015-08-01")),linetype="dashed")

# Switzerland
load("ch_dfms.RData")
ch_<-docvars(ch_dfm)
ch_$gessler_hunger=ch_$gessler_hunger*100

ch_$time<- as.Date(paste0("20",ch_$ym,"-01"), "%Y-%m-%d")
ch_<-ch_ %>% group_by(party,ym) %>% dplyr::mutate(total=dplyr::n()) %>% subset(total>4)
ch_<-subset(ch_,ch_$time<as.Date("2018-03-31"))
ch2<-ch_ %>% dplyr::rename(party2=party)

ch_plot<-ggplot(data=ch_,mapping=aes(x=time,y=gessler_hunger))+
  geom_smooth(data=ch2,mapping=aes(x=time,y=gessler_hunger,group=party2),alpha=0.6,method="loess",color="gray",se=F,size=0.3)+
 geom_smooth(mapping=aes(x=date,alpha=0.25,color=party,fill=party),method="loess",size=0.5)+
    stat_summary(fun.y="mean",geom="point",size=1,aes(color=party))+
scale_x_date(name="Date", date_breaks = "year", date_labels="%Y")+
 scale_y_continuous(name="Salience in %") +theme_minimal()+ theme(legend.position="none")+
 scale_color_manual(name="Party", values=c("gold","peru", "cornflowerblue","purple", "seagreen", "red", "dimgray"), labels=c("bdp"="BDP","fdp_ch"="FDP","gr_ch"="Green Party","svp"="SVP","cvp"="CVP","greenliberal"="Green Liberal Party","sp"="SPS"))+
scale_fill_manual(values=c("gold","peru", "cornflowerblue","purple", "seagreen", "red", "dimgray"))+ theme_minimal()+theme(legend.position="none")+
 ggtitle("Salience of immigration in Switzerland")+
  facet_wrap(~party,labeller=labeller(party=party_names_ch))+
  coord_cartesian(ylim=c(0,100))+
  geom_vline(aes(xintercept=as.Date("2015-08-01")),linetype="dashed")


# combine to final graph
sal<- cowplot::plot_grid(at_plot,de_plot,ch_plot, labels = "AUTO",ncol=1,align="v",rel_heights=c(1,1.5,1.5))
sal


```


## Dynamics of salience

*see Stata do-file*

## Party positions on immigration over time



```{r position-figure-cis, fig.align='center', fig.show="hold", fig.cap="\\label{fig:pos}Estimated party positions on immigration in 3 countries",fig.width=8,fig.height=12,fig.pos="!htp"}

# main graphs for position

load("scores_at.Rdata")
df_scores_at$time <- as.Date(paste0("20",df_scores_at$ym,"-01"), "%Y-%m-%d")
df_scores_at<-subset(df_scores_at,df_scores_at$time<as.Date("2018-03-31"))
at2<-df_scores_at %>% dplyr::rename(party2=party)

# Austria
at_plot<-ggplot(df_scores_at, aes(x=time, y=keyness_predicted, group=party, color=party))+
  geom_smooth(data=at2,mapping=aes(x=time,y=keyness_predicted,group=party2),alpha=0.6,method="loess",color="gray",se=F,size=0.3)+
  geom_smooth(aes(x=date,fill=party),method="loess")+
scale_x_date(name="Date", date_breaks = "year", date_labels="%Y")+
  scale_y_continuous(name="Position on immigration") +
  stat_summary(fun.y="mean",geom="point",aes(alpha=0.8),size=1)+
 scale_color_manual(name="Party", values=c("cornflowerblue","seagreen","purple","black","red"))+
 scale_fill_manual(values=c("cornflowerblue","seagreen","purple","black","red"))+
 theme_minimal()+theme(legend.position="none") +
 facet_wrap(~party,labeller=labeller(party=party_names_at))+
 ggtitle("Positions on immigration in Austria")+
 coord_cartesian(ylim=c(-1,1))+
  geom_vline(aes(xintercept=as.Date("2015-08-01")),linetype="dashed")

# Germany
load("scores_de.Rdata")
df_scores_de$time <- as.Date(paste0("20",df_scores_de$ym,"-01"), "%Y-%m-%d")
df_scores_de<-subset(df_scores_de,df_scores_de$time<as.Date("2018-03-31"))
de2<-df_scores_de %>% dplyr::rename(party2=party)


de_plot<-ggplot(df_scores_de, aes(x=time, y=keyness_predicted, group=party, color=party))+
  geom_smooth(data=de2,mapping=aes(x=time,y=keyness_predicted,group=party2),alpha=0.6,method="loess",color="gray",se=F,size=0.3)+
geom_smooth(aes(x=date,fill=party),method="loess")+
scale_x_date(name="Date", date_breaks = "year", date_labels="%Y")+
  scale_y_continuous(name="Position on immigration") +
  stat_summary(fun.y="mean",geom="point",aes(alpha=0.8),size=1)+
 scale_color_manual(name="Party", values=c("cornflowerblue","black","dimgray","gold","seagreen","purple","red"))+
 scale_fill_manual(values=c("cornflowerblue","black","dimgray","gold","seagreen","purple","red"))+
   theme_minimal()+theme(legend.position="none") +
 facet_wrap(~party,labeller=labeller(party=party_names_de))+
 ggtitle("Positions on immigration in Germany")+
 coord_cartesian(ylim=c(-1.5,1))+
  geom_vline(aes(xintercept=as.Date("2015-08-01")),linetype="dashed")

# Switzerland
load("scores_ch.Rdata")
df_scores_ch$time <- as.Date(paste0("20",df_scores_ch$ym,"-01"), "%Y-%m-%d")
df_scores_ch<-subset(df_scores_ch,df_scores_ch$time<as.Date("2018-03-31"))
ch2<-df_scores_ch %>% dplyr::rename(party2=party)

ch_plot<-ggplot(df_scores_ch, aes(x=time, y=keyness_predicted, group=party, color=party))+
  geom_smooth(data=ch2,mapping=aes(x=time,y=keyness_predicted,group=party2),alpha=0.6,method="loess",color="gray",se=F,size=0.3)+
  geom_smooth(aes(x=date,fill=party),method="loess")+
scale_x_date(name="Date", date_breaks = "year", date_labels="%Y")+
  scale_y_continuous(name="Position on immigration") +
  stat_summary(fun.y="mean",geom="point",aes(alpha=0.8),size=1)+
scale_color_manual(name="Party", values=c("peru",  "cornflowerblue",  "seagreen", "red", "dimgray"))+
scale_fill_manual(values=c("peru", "cornflowerblue", "seagreen", "red", "dimgray"))+ theme_minimal()+theme(legend.position="none") +
  facet_wrap(~party,labeller=labeller(party=party_names_ch))+
 ggtitle("Positions on immigration in Switzerland")+
 coord_cartesian(ylim=c(-1,1))+
  geom_vline(aes(xintercept=as.Date("2015-08-01")),linetype="dashed")

# combine to final graph

pos <- cowplot::plot_grid(at_plot,de_plot,ch_plot, labels = "AUTO",ncol=1,align="v",rel_heights=c(1,1.5,1))
pos
```



## Dynamics of positional change

*see Stata do-files*


# Appendix


## Classifier Accuracy for Austria, Germany and Switzerland



```{r}

rm(list=ls())

load("classifier_de_accuracy.RData")
load("accuracy_de.RData")

SVM<-append(classifier$byClass,classifier$overall[["Accuracy"]])
germany_accuracy<-cbind(class_wise,SVM)
knitr::kable(germany_accuracy[c(1,2,12,11),], digits=2, caption="\\label{tab:accde}Classification Accuracy Germany",col.names=c("GH-T","GH","RP-T","RP","RM-T","RM","SVM"),longtable=T) %>% kable_styling() %>% row_spec(row = 0, bold=T)

load("accuracy_at.RData")
knitr::kable(class_wise[c(1,2,12,11),], digits = 2, caption="\\label{tab:accat}Classification Accuracy Austria",col.names=c("GH-T","GH","RP-T","RP","RM-T","RM"),longtable=T) %>% kable_styling() %>% row_spec(row = 0, bold=T)
```



```{r}
load("accuracy_ch.RData")
knitr::kable(class_wise[c(1,2,12,11),], digits = 2, caption="\\label{tab:accch}Classification Accuracy Switzerland",col.names=c("GH-T","GH","RP-T","RP","RM-T","RM"),longtable=T) %>% kable_styling() %>% row_spec(row = 0, bold=T)
```



## Arellano Bond Tests


*see Stata do-file*



## Robustness checks for regressions

*see Stata do-file*




## Party Positions

```{r,output='asis'}

# Comparision table for positions

# load data
load("scores_de_monthly.Rdata")
party_dispersion_immig_de<-ddply(df_scores_de_monthly, .(party),summarize, immig=mean(keyness_predicted),sd_immig=sd(keyness_predicted))

load("scores_ch_monthly.Rdata")
party_dispersion_immig_ch<-ddply(df_scores_ch_monthly, .(party),summarize, immig=mean(keyness_predicted),sd_immig=sd(keyness_predicted))

load("scores_at_monthly.Rdata")
party_dispersion_immig_at<-ddply(df_scores_at_monthly, .(party),summarize, immig=mean(keyness_predicted),sd_immig=sd(keyness_predicted))

party_dispersion_immig<-bind_rows(party_dispersion_immig_at,party_dispersion_immig_de,party_dispersion_immig_ch,.id="id")

# load polcon data
polcon <- haven::read_dta("coresentences_data_190718_clean.dta")
polcon<-dplyr::filter(polcon,country %in% c(4,1,6)) %>%  mutate(country=as.character(country)) %>%
                                                           mutate(id=car::recode(country,"1=1;4=2;6=3"))
polcon$year <- polcon$year_election
polcon <- dplyr::filter(polcon, year > 2010)

polcon$year<-as.integer(polcon$year)
polcon$crisis<-recode(polcon$year,"c(2011,2013)='precrisis';c(2015,2017)='postcrisis'")
polcon$dir_immig <- as.numeric(polcon$direction_agg_all)
# just select the variables that are neccessary
polcon$party<-as.character(polcon$partys_all) %>% car::recode("'40001'='cdu';'40002'='spd';'40003'='fdp'; '40004'='gruene';'40005'='linke';'40007'='afd';'10001'='ovp';'10002'='spo';'10003'='fpo';
                          '10004'='gruene';'10009'='neos';'10014'='pilz';'60001'='svp';'60002'='fdp_ch';'60003'='sp'; '60004'='cvp'; '60006'='greens_ch';'60009'='greenliberal';
                          '60010'='bdp'")
polcon <- dplyr::select(polcon, id, crisis, party, dir_immig) %>% spread(key="crisis",value="dir_immig") %>% mutate(id=as.character(id))
party_dispersion_immig_new<-left_join(party_dispersion_immig,polcon)


# create table
party_dispersion_immig_new %>% mutate(party=car::recode(party,"'pilz'='Pilz';'gruene'='Green Party';'spo'='SPÖ';'ovp'='OVP';'fpo'='FPÖ';'neos'='NEOS';'afd'='AfD';'linke'='Left Party';'spd'='SPD';'cdu'='CDU';'fdp'='FDP';'csu'='CSU';'bdp'='BDP';'fdp_ch'='FDP';'greens_ch'='Green Party';'svp'='SVP';'cvp'='CVP';'greenliberal'='Green Liberal Party';'sp'='SPS'")) %>% dplyr::select(party,immig,sd_immig,precrisis,postcrisis) %>%
  knitr::kable(format='html', booktab = T,longtable=T, caption = "\\label{tab:pos-stability}Average and Stability of party positions",digits = c(2,2, 2, 2),col.names = c("Party", "Avg. Position","SD","POLCON I","POLCON II"))%>%
  kableExtra::kable_styling() %>% group_rows("Austria", 1, 5) %>%
 group_rows("Germany", 6, 12) %>% group_rows("Switzerland", 13, 17)

```


